package com.demo.core.listenerCore;

import com.demo.config.LogInit;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;

//@Aspect
public class RequestLogAspest {

    private Logger logger = LogInit.getInstance();

//    @Pointcut(value = "execution(io.restassured.response.Response com.demo.core.BaseApiCore.*(..))")
    public void aspectPointCut(){
    }

//    @Around(value = "aspectPointCut()")
    public Object aroundMethod(ProceedingJoinPoint pJp) throws Throwable {
        // 请求开始时间
        long startTime = System.currentTimeMillis();

        Object returnValue = pJp.proceed();

        //请求结束时间
        long elapsedTime = System.currentTimeMillis() - startTime;
        logger.info(String.format("Request Duration: %sms", elapsedTime) + "\r\n");
        return returnValue;
    }
}
